package cn.com.qiancheng.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import cn.com.qiancheng.dto.Question;
import cn.com.qiancheng.util.DbUtil;

public class QuestionDao {
	public Question sreachQuestion(int id) {

		Question question = null;
		try {
			Connection con = DbUtil.openConnection();
			String sql = "SELECT q_id,q_content FROM t_question WHERE q_id = ?";
			PreparedStatement stat = con.prepareStatement(sql);
			stat.setInt(1, id);
			ResultSet rs = stat.executeQuery();
			if (rs.next()) {
				question = new Question();
				question.setContent(rs.getString("q_content"));
				question.setId(rs.getInt("q_id"));
				question.setList(new AnswerDao().searchAnswer(question.getId()));
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
			try {
				DbUtil.closeConnection();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		return question;
	}
}
